<template>
	<view class="content">
		<!-- 导航栏 -->
		<u-navbar :is-back="true" :is-fixed="true" @click="search" title="搜索" back-icon-color="white"
			title-color="white" :background="background" :border-bottom="false" />

		<view class="u-p-20 search-box">
			<u-search placeholder="关键字" v-model="keyword" :focus="true" :show-action="true" :animation="true"
				@search="searchKeyword"></u-search>
		</view>

		<!-- 关键字 -->
		<view class="u-p-20 keyword-box u-m-t-10" v-if="keywordList.length">
			<view class="u-m-b-20">
				<text>历史搜索</text>
			</view>
			<view class="keyword-list">
				<u-tag :text="item" mode="light" type="info" class="u-m-l-10 u-m-t-20" shape="circle" size="mini"
					closeable v-for="(item,index) in keywordList" @close="tagClick(index)" />
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundImage: 'linear-gradient(90deg, rgb(42,132,255), rgb(234,175,200))'
				},
				keyword: null,
				keywordList: uni.getStorageSync('keywordList')||[]
			};
		},
		methods: {
			tagClick(index) {
				this.keywordList.splice(index, 1);
				uni.setStorageSync('keywordList',this.keywordList)
			},
			search() {
				uni.navigateTo({
					url: `/pages/good/goodsList/goodsList?key=${this.keyword}`
				})
			},
			searchKeyword() {
				let result=this.keywordList.indexOf(this.keyword)
				if(result<0){
					this.keywordList.push(this.keyword)
					uni.setStorageSync('keywordList',this.keywordList)
				}
				uni.navigateTo({
					url: `/pages/good/goodsList/goodsList?key=${this.keyword}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #F8F8F8;
		height: 100vh;
	}

	.search-box {
		width: 100vw;
		background-color: #FFFFFF;
	}

	.keyword-box {
		width: 100vw;
		background-color: #FFFFFF;
		min-height: 200upx;
	}
</style>